package jeconbond.experiment.market.equilibrium.process;

import java.util.Map;

import jeconbond.economic.market.agent.service.SpySellsAgent;
import jeconbond.economic.market.strategy.ConcurrentBasedPerformPriceStrategy.AvaluateMarketPriceAgent;
import jeconbond.economic.resources.IResourceType;
import jeconbond.economic.systems.market.IMarketResourceRedestributionSystem;
import jeconbond.experiment.market.equilibrium.MooreExperimentSettings;
import jeconbond.experiment.process.BaseJEBExperimentContext;
import laboratoryQ.experiment.process.IExperimentContextFactory;
import laboratoryQ.experiment.process.IExperimentContext;
import laboratoryQ.experiment.settings.IExperimentSettings;

public class MooreExperimentContext extends BaseJEBExperimentContext implements IMooreExperimentContext, IExperimentContextFactory {
	public static final IExperimentContextFactory FACTORY_INSTANCE = new MooreExperimentContext();
	
	private SpySellsAgent spySellsAgent;
	private AvaluateMarketPriceAgent avaluateMarketPriceAgent;

	public MooreExperimentContext(MooreExperimentSettings experimentSettings) {
		super(experimentSettings);
		
		avaluateMarketPriceAgent = new AvaluateMarketPriceAgent(
				experimentSettings.resources,
				getRRS()
		);
		
		spySellsAgent = new SpySellsAgent(
				getRRS(),
				getNextStepCommander().stepCounter,
				experimentSettings.resources
		);
		addServiceAgent(spySellsAgent);
		addServiceAgent(avaluateMarketPriceAgent);
	}

	// 4 create as factory
	protected MooreExperimentContext() {}

	@Override
	public MooreExperimentSettings getExperimentSettings() {
		return (MooreExperimentSettings) super.getExperimentSettings();
	}

	@Override
	public IMarketResourceRedestributionSystem getRRS() {
		return (IMarketResourceRedestributionSystem) super.getRRS();
	}

	@Override
	public SpySellsAgent getSpySellsAgent() {
		return spySellsAgent;
	}

	@Override
	public Map<IResourceType, double[]> getConcurrentPricesMap() {
		return avaluateMarketPriceAgent.getConcurrentPrices();
	}
	
	@Override
	public IExperimentContext newContext(IExperimentSettings settings) {
		return new MooreExperimentContext((MooreExperimentSettings) settings);
	}
}
